import kotlin.reflect.KProperty
import kotlin.collections.MutableMap

class PoliteString(val dataSource: MutableMap<String, Any>){
    operator fun getValue(thisRef: Any?, property: KProperty<*>) = (dataSource[property.name] as? String)?.replace(
        "stupid", "s*******")?: ""

    operator fun setValue(thisRef: Any, property: KProperty<*>, value: String) {
        dataSource[property.name] = value
    }
}

class PostComment(dataSource: MutableMap<String, Any>){
    val title: String by dataSource
    var likes: Int by dataSource
    val comment: String by PoliteString(dataSource)
    override fun toString() = "Title: $title Likes:$likes Comment:$comment"
}

val dataList = listOf<MutableMap<String, Any>>(
    mutableMapOf("title" to "Using delegation", "likes" to 2, "comment" to "keep it simple,stupid"),
    mutableMapOf("title" to "Using Inheritance", "likes" to 3, "comment" to "prefer delegation"), )

val forPost1 = PostComment(dataList[0])
val forPost2 = PostComment(dataList[1])


println(forPost1)
forPost1.likes++
println(forPost2)
forPost2.likes++
println(forPost2)
